package com.oms.util;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.PropertyUtils;






public class POtoVOUtil {
	
	
	/**
	 * 输入po对象poObj，voClass，将Po集合转化为Vo对象,返回Vo对象(可以变换位置)
	 * @param poObj
	 * @param voClass
	 * @return
	 */
	public static Object copyObject ( Object poObj , @SuppressWarnings("rawtypes") Class voClass){       
        Object voObj =null;
                try {
					voObj = voClass.newInstance();
				} catch (InstantiationException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (IllegalAccessException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}  
				try {
					PropertyUtils.copyProperties(voObj, poObj);
				} catch (IllegalAccessException
						| InvocationTargetException
						| NoSuchMethodException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

        return voObj;
    }
	
	/**
	 * 输入po对象集合poList和vo类，voClass，将Po对象集合转化为Vo对象集合，返回Vo集合(可以变换位置)
	 * @param poList
	 * @param voClass
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static List copyList (List <? extends Object> poList , Class voClass){
        List voList=new ArrayList();
        Object voObj =null;
        for(Object poObj:poList){
			try {
				voObj = voClass.newInstance();
			} catch (InstantiationException | IllegalAccessException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			try {
				PropertyUtils.copyProperties(voObj, poObj);
			} catch (IllegalAccessException | InvocationTargetException
					| NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

        }
//        System.out.println("__________转换了 "+voList.size()+"个对象");
        return voList;
	}
         


}
